package board_mvc.handler;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import board.BoardDBBean;
import board.BoardDataBean;
@Controller
public class ModifyProAction implements CommandHandler{
	@Resource( name="instance" )
	BoardDBBean dao;
	@RequestMapping("/modifyPro")
	@Override
	public ModelAndView process(HttpServletRequest request, HttpServletResponse response) {
		Map<String,Object>map=new HashMap<String, Object>();
		try {
			request.setCharacterEncoding( "euc-kr" );
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int pageNum = Integer.parseInt( request.getParameter( "pageNum" ) );		
		BoardDataBean dto=new BoardDataBean();
		dto.setSubject(request.getParameter("subject"));
		dto.setEmail(request.getParameter("email"));
		dto.setContent(request.getParameter("content"));
		dto.setPasswd(request.getParameter("passwd"));
		dto.setNum(Integer.parseInt(request.getParameter("num")));		
		// BoardDBBean dao = BoardDBBean.getInstance();
		int result = dao.updateArticle( dto );				
		map.put("result", result);
		if(result!=0){
			map.put("pageNum", pageNum);
		}
		return new ModelAndView("modifyPro",map);
	}

}